#ifndef _GOVT_SHOP_HPP
#define _GOVT_SHOP_HPP
/*******************************************************************************
 ** Name: shop.hpp                                                            **
 ** Description: WorldObject-derived container objects                        **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the LICENSE file within             **
 ** this distribution or at $WIKI/display/GOVT/License-software.              **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $GAME_DIR/LICENSE.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 ** Copyright (c) 2009-2011  Barry Gian James <gian@gamingods.net>            **
 ** All rights reserved.                                                      **
 ******************************************************************************/
// Modified $Date: 2011-11-24 00:07:02 -0700 (Thu, 24 Nov 2011) $ by $Author: unknown $
#define shop_hpp_ID   "$Id: shop.hpp 63608 2011-11-24 07:07:02Z unknown $"

#include "room.hpp"
#include "weapon.hpp"
#include "item.hpp"
#include "magic.hpp"
#include "Range.hpp"
#include "economy.hpp"

#define DEFAULT_SELL_PROFIT	1.5		// 150%
#define DEFAULT_BUY_PROFIT	0.7		// 70%
#define DEFAULT_GOLD_MULT	100000	// 100k * caliber

//! Condensed item struct for shop goods
struct ShopGoods
{
	entity_t	itemID;	// from DB
	std::string name;
};

// should employees be configured for the hours and days they work?
// this would require a certain number of employees to stay open longer
class Employee
{
public:
	entity_t &	NPC() { return npc; }
	int & Pay() { return pay; }
	std::string & Position() { return position; }

private:
	entity_t	npc;
	int		pay;	// monthly pay
	std::string position;
};

//! @class Shop
//! @brief Basic business shop class
// TODO how to make this polymorphic class work with ORM?
class Shop : public Room
{
public:
	Shop();

	size_t &	MarketValue() { return marketValue; }
	entity_t &	Stock() { return stock; }
	size_t &	StockIssued() { return stockIssued; }
	entity_t &	Loan() { return loan; }
	entity_t &	Bonds() { return bonds; }
	CreditRating & CreditScore() { return creditRating; }

	// Getters
	entity_t	ShopKeeper() { return shopKeeper; }
	WpnType *	WeaponTypes() { return buyWpnType; }
	MType *		MagickTypes() { return buyMagickType; }
	ItemType *	ItemTypes() { return buyItemType; }
	AmmoType *	AmmoTypes() { return buyAmmoType; }
	double		SellProfit() { return sellProfit; }
	double		BuyProfit() { return buyProfit; }
	Range *		Hours() { return hours; }
	ushort &	Caliber() { return caliber; }

	// Setters
	void		ShopKeeper(entity_t i) { shopKeeper = i; }
	void		WeaponTypes(WpnType w);
	void		MagickTypes(MType );
	void		ItemTypes(ItemType);
	void		AmmoTypes(AmmoType);
	void		SellProfit(int s) { sellProfit = s; }
	void		BuyProfit(int s) { buyProfit = s; }
	void		Hours(int open, int close);
	void		Caliber(ushort c) { caliber = c; }

	void		Buy(WorldObject *);
	void		Sell(WorldObject *);


protected:
	entity_t	shopKeeper;
	// TODO These need to be refined
	WpnType	*	buyWpnType;
	MType	*	buyMagickType;
	ItemType*	buyItemType;
	AmmoType*	buyAmmoType;
	double		sellProfit;
	double		buyProfit;
	Range	*	hours;		// is this necessary and what are incentives/costs?
	ushort		caliber;	//!< caliber of store. determines how much $$ onhand
	size_t		scratch;
	std::list<ShopGoods> inventory;
	std::vector<Employee> employees;
	size_t		marketValue;
	entity_t	stock;		// idstock from DB
	size_t		stockIssued;	// number of stocks issued
	entity_t	loan;		// any loan taken out
	entity_t	bonds;		// bonds issued
	CreditRating creditRating;
	unsigned long earnings;
	unsigned long expected_earnings;
	bool		auto_buy;	// will shop purchase items from players?
};

//! @class Bank
//! @brief The derived class for player-ran banking
class Bank : public Room
{
public:

private:
	entity_t	owner;
	entity_t	idbank;	// idbank from db
	entity_t	idfcba;	// fcbaID from db certificate
	size_t		reserve;
};

#endif /* _GOVT_SHOP_HPP */
